﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace CAD.DAO
{
    public class DAOSubarea
    {
        public int Insertar(string SNOMBRE, int ICONCURRENCIA, int LAREAS_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LSUBAREAS_ID";
            prmA.Direction = ParameterDirection.Output;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.String;
            prmB.ParameterName = "@SNOMBRE";
            prmB.Value = SNOMBRE;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.Int32;
            prmC.ParameterName = "@ICONCURRENCIA";
            prmC.Value = 1;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@LAREAS_ID";
            prmD.Value = LAREAS_ID;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            DbParameter prmDe = new SqlParameter();
            prmDe.DbType = DbType.Int32;
            prmDe.ParameterName = "@iEvento";
            prmDe.Value = 1;
            prmDe.Direction = ParameterDirection.Input;
            lstParametros.Add(prmDe);

            SQLConexion conProxy = new SQLConexion();
            if (conProxy.EjecutarDML(lstParametros, "dbo.SPABM_SUBAREAS"))
                return Convert.ToInt32(prmA.Value);
            return -1;

        }
        public int Insertar(int LSUBAREAS_ID, string SNOMBRE, int ICONCURRENCIA, int LAREAS_ID, SqlTransaction transaccion)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LSUBAREAS_ID ";
            prmA.Direction = ParameterDirection.Output;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.String;
            prmB.ParameterName = "@SNOMBRE";
            prmB.Value = SNOMBRE;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.Int32;
            prmC.ParameterName = "@ICONCURRENCIA";
            prmC.Value = 1;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@LAREAS_ID";
            prmD.Value = LAREAS_ID;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            DbParameter prmDe = new SqlParameter();
            prmDe.DbType = DbType.Int32;
            prmDe.ParameterName = "@iEvento";
            prmDe.Value = 1;
            prmDe.Direction = ParameterDirection.Input;
            lstParametros.Add(prmDe);

            SQLConexion conProxy = new SQLConexion();
            if (conProxy.EjecutarDML(lstParametros, "dbo.SPABM_SUBAREAS", transaccion))
                return Convert.ToInt32(prmA.Value);
            return -1;

        }
        public bool Actualizar(int LSUBAREAS_ID, string SNOMBRE, int ICONCURRENCIA, int LAREAS_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LSUBAREAS_ID";
            prmA.Value = LSUBAREAS_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.String;
            prmB.ParameterName = "@SNOMBRE";
            prmB.Value = SNOMBRE;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.Int32;
            prmC.ParameterName = "@ICONCURRENCIA";
            prmC.Value = ICONCURRENCIA;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@LAREAS_ID";
            prmD.Value = LAREAS_ID;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            DbParameter prmDe = new SqlParameter();
            prmDe.DbType = DbType.Int32;
            prmDe.ParameterName = "@iEvento";
            prmDe.Value = 1;
            prmDe.Direction = ParameterDirection.Input;
            lstParametros.Add(prmDe);

            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarDML(lstParametros, "dbo.SPABM_SUBAREAS");
        }
        public bool Eliminar(int LSUBAREAS_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LSUBAREAS_ID";
            prmA.Value = LSUBAREAS_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);
            DbParameter prmDe = new SqlParameter();
            prmDe.DbType = DbType.Int32;
            prmDe.ParameterName = "@iEvento";
            prmDe.Value = 3;
            prmDe.Direction = ParameterDirection.Input;
            lstParametros.Add(prmDe);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarDML(lstParametros, "dbo.SPABM_SUBAREAS");
        }
        public DataSet TraerSubarea()
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 4;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_SUBAREAS");
        }
        public DataSet TraerSubareaXId(int LCENTRODECOSTOS_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LSUBAREAS_ID";
            prmA.Value = LCENTRODECOSTOS_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 5;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_SUBAREAS");
        }
        public DataSet TraerSubareaXNombre(string SNOMBRECENTRODECOSTO)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.String;
            prmA.ParameterName = "@SNOMBRE";
            prmA.Value = SNOMBRECENTRODECOSTO;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento ";
            prmD.Value = 7;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_SUBAREAS");
        }
    }
}
